<template>
	<view class="page" v-if="!loadding" :style="{minHeight:windowHeight+'px'}">
		
		<view class="top-head">
			<view class="head-l">
				<image src="../../../static/app/jiaotou1.png" @click="gotoPage('/pages/user/index/index')" mode=""></image>
			</view>
			<view class="head-title">我的司机</view>
			<view class="head-r" @click="gotoPage('/pages/user/add-driver/add-driver')">+ 添加司机</view>
		</view>

		<view class="list-wrap">
			<!-- 		<block v-for="(item,index) in 5" :key="index">
				<view class="list-item">
					<view class="item-info">
						<view class="info-avatar">
							<image src="../../../static/app/logo.png" mode=""></image>
						</view>
						<view class="info">
							<view class="item-name">
								吴彦祖
							</view>
							<view class="item-tag">
								<text>26岁</text>
								<text>|</text>
								<text>三年驾龄</text>
								<text>|</text>
								<text>C1</text>
								<text>|</text>
								<text>广西桂林</text>
							</view>
						</view>
					</view>
					<view class="item-btn">
						立即沟通
					</view>
				</view>
			</block> -->
			<!-- <view class="list-item">
				<view class="item-info">
					<view class="info-avatar">
						<image src="../../../static/app/logo.png" mode=""></image>
					</view>
					<view class="info">
						<view class="item-name">
							吴彦祖
						</view>
						<view class="item-tag">
							<text>26岁</text>
							<text>|</text>
							<text>三年驾龄</text>
							<text>|</text>
							<text>C1</text>
							<text>|</text>
							<text>广西桂林</text>
						</view>
					</view>
				</view>
				<view class="item-btn">
					立即沟通
				</view>
			</view> -->
			<view class="list-item" v-for="(item,index) of driver">
				<view class="item-info">
					<view class="info-avatar">
						<image src="../../../static/app/logo.png" mode=""></image>
					</view>
					<view class="info">
						<view class="item-name">
							<view>
								{{item.realname}}
							</view>							
						</view>
						<view class="item-tag">
							<text>{{item.age}}岁</text>
							<text>|</text>
							<text>驾龄:{{item.age_name}}</text>
							<text>|</text>
							<text>{{item.type_name}}</text>
							<text>|</text>
							<text>{{item.address}}</text>
						</view>
						
					</view>
					<view class="status">
						
						<view class="delete">
							<image @click="deleteCar(item.id)" src="../../../static/delete.png"></image>
						</view>
					</view>
				</view>
				<!-- <view class="item-btn">
					立即沟通
				</view> -->
			</view>
		</view>
		<!-- 没有记录 -->
		<view class="nullmsg d-c-c p30" v-if="driver.length == 0 ">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<view v-else v-show="isLoadMore">
			<uni-load-more :loadingType="loaddingOn"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				loadding: false,
				driver:[],
				windowHeight:'',
				noClick:true,
				isLoadMore: false, //是否加载中
				page: 1,
				pagesize: 10,
				loaddingOn:0,
			};
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
				}
			});
		},
		onShow() {
			this.getData();
			this.page = 1;
			this.driver = [];
		},
		onPullDownRefresh() {
			this.page = 1;
			this.driver = [];
			this.getData();
			setTimeout( () => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.page += 1
				this.getData();
			}
		},
		methods: {
			/* 删除车辆 */
			deleteCar(id){
				let self = this; 
				uni.showModal({
					title:'温馨提示',
					content:'是否要删除司机信息',
					success: function (res) {
					       if (res.confirm) {
					           self._post('user.index/del_mydriver',
					           {
					           	id:id
					           },
					            function(res) {
									self.getData();
									//self.gotoPage('/pages/user/my-driver/my-driver')
					           });
					       } else if (res.cancel) {
							   
					       }
					   }
				})			 				
			},
			/*获取数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('user.index/my_driver', {page:self.page}, function(res) {
					console.log(res);
					//self.driver=res.data.driver.data;
					if (res.data.driver.data) {
						self.driver = self.driver.concat(res.data.driver.data)
						if (res.data.driver.data.length < res.data.driver.per_page) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
							self.isLoadMore = true
							self.loaddingOn = 2
						} else {
							self.isLoadMore = false
						}
					} else {
						self.isLoadMore = true
						self.loaddingOn = 2
					}
					// //console.log(res.data.driver)
					self.loadding = false;
					uni.hideLoading();
				});
			},
			/*跳转页面*/
			gotoPage(path) {
				let self = this;
				if (path.startsWith('/')) {
					uni.navigateTo({
						url: path
					});
				} else {
					self[path]();
				}
			}
		}
	}
</script>

<style lang="scss">
	@import 'my-driver.scss';
</style>
